package com.example.spring_principle.config;

import com.example.spring_principle.model.Dog;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.annotation.ApplicationScope;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.context.annotation.SessionScope;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/7/31
 * Time: 15:28
 */
@Configuration
public class DogConfig {
    @Bean
    public Dog dog(){
        Dog dog = new Dog();
        dog.setName("旺旺");
        return dog;
    }

    // 单例作用域
    @Bean
//    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    @Scope("singleton")
    public Dog singleDog() {
        return new Dog();
    }

    // 多例作用域
    @Bean
//    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @Scope("prototype")
    public Dog prototypeDog() {
        return new Dog();
    }

    // 请求作用域
    @Bean
    @RequestScope
    public Dog requestDog() {
        return new Dog();
    }

    // session作用域
    @Bean
    @SessionScope
    public Dog sessionDog() {
        return new Dog();
    }


    // application作用域
    @Bean
    @ApplicationScope
    public Dog applicationDog() {
        return new Dog();
    }


}
